/* pollsrv.c */
#include <stdio.h>
#include <sys/types.h> 
#include <sys/socket.h> 
#include <sys/un.h>
#include <string.h>
#include <stdlib.h>
#include <sys/time.h>
#include <fcntl.h>
#include <fstream>
#include <signal.h>
#include <sys/stat.h>
#include <string>
#include <iostream>
#include <dirent.h>
#include <errno.h>
#include <sys/param.h>
#include <fcntl.h>
#include <netinet/tcp.h>
#include <sstream>
#include <time.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <net/if.h>

using namespace std;

int panda_set(int sock, char *k, int klen, char *v, int vlen)
{ 
      unsigned ulen = 3*sizeof(unsigned) + klen + vlen;
      char *buf = g_malloc(ulen +1 ) ;
  //  method + ihash + key +value
      bcopy(&items, *buf + usedlen, uint_len);  // items
      usedlen += uint_len;
      bcopy(&klen, *buf + usedlen, uint_len);  // klen
      usedlen += uint_len;
      bcopy(k, *buf + usedlen, klen);          // k
      usedlen += klen;
      bcopy(&vlen, *buf + usedlen, uint_len);    // vlen
      usedlen += uint_len;
      bcopy(retval, *buf + usedlen, vlen);     //v  

      int iret = write(sockfd, buf, ulen);
      g_free(buf); 
      if(iret == -1)
      { 
              perror("send");
              return -1;
      }
      return 0;
}


int main(int argc, char *argv[])
{

	struct hostent *host = gethostbyname("localhost") ;
	struct sockaddr_in in_addr;
	if(host != NULL)
	{
		in_addr.sin_addr.s_addr = *((u_long *)(host->h_addr));
		cout << inet_ntoa(in_addr.sin_addr) <<endl;
	}
        else
             return -1;

      if((sockfd = socket(AF_INET,SOCK_STREAM,0))==-1)
      {
         perror("socket");
	 exit(1);
      }
      their_addr.sin_family = AF_INET;
      their_addr.sin_port = htons( atoi(argv[2]));
      their_addr.sin_addr = *((struct in_addr *)he->h_addr);
      bzero(&(their_addr.sin_zero),8);
      if(connect(sockfd,(struct sockaddr *)&their_addr, sizeof(struct sockaddr)) ==-1){
	      perror("connect");
	      exit(1);
      }

      
      fclose(sockfd);
      return 0;

}

